package com.chinaoly.baotou.common.utils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;

import java.awt.*;

/**
 * @description 验证码生成工具类
 * Create by sunlm
 * on 2022-10-20 13:05
 * Make small but daily progress
 */
public class VerificationCodeUtils {

    /**
     * 生成自定义规则的验证码
     */
    public static void generateCustomVerificationCode() {
        /**参数分别是宽、高、验证码个数，横线干扰个数**/
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(300, 100, 6, 10);
        /** 可以自定义生成的内容区间,个数,字体样式,背景颜色等等 **/
        lineCaptcha.setBackground(Color.GREEN);
        /**只会在0-9中产生验证码的内容，内容个数为6**/
        RandomGenerator randomGenerator = new RandomGenerator("0123456789", 6);
        lineCaptcha.setGenerator(randomGenerator);
        String lineCaptchaCode = lineCaptcha.getCode();
        System.out.println(lineCaptchaCode);
        lineCaptcha.write("D:\\lineCaptcha2.png");
    }
    public static void main(String[] args) {
        generateCustomVerificationCode();
    }
}
